package MovingAverage;

import java.util.ArrayDeque;
import java.util.Queue;

public class Solution {
    class MovingAverage {

        /** Initialize your data structure here. */
        Queue<Integer> queue = new ArrayDeque<>();
        int size;
        double cur = 0;
        public MovingAverage(int size) {
            this.size = size;
        }

        public double next(int val) {
            queue.add(val);
            cur+=val;
            if(queue.size()>size) {
                cur-=queue.poll();
            }
            return cur/queue.size();
        }
    }
}
